package com.itheima.bean;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * ClassName: MyImportSelector
 * Description:
 * Date: 2023/03/22 PM 9:57:00
 * <p>
 * project: springboot
 * package: com.itheima.bean
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class MyImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        // System.out.println("================================================");
        // System.out.println("提示: " + metadata.getClassName());
        // System.out.println(metadata.hasAnnotation("org.springframework.context.annotation.Configuration"));
        // Map<String, Object> attributes = metadata.getAnnotationAttributes("org.springframework.context.annotation.ComponentScan");
        // System.out.println(attributes);
        // System.out.println("================================================");

        // 各种条件的判定，判定完毕后，决定是否装载指定的 bean
        boolean flag = metadata.hasAnnotation("org.springframework.context.annotation.Configuration");
        if (flag) {
            return new String[]{"com.itheima.bean.Dog"};
        }
        return new String[]{"com.itheima.bean.Cat"};
    }
}
